package xiaohu.day6.HJ65;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String str1 = scanner.nextLine();
            String str2 = scanner.nextLine();
            if (str1.length() > str2.length()) {
                String temp=str1;
                str1=str2;
                str2=temp;
            }

            int[][] dp = new int[str1.length() + 1][str2.length() + 1];
            for (int i = 1; i <= str1.length(); i++) {
                for (int j = 1; j <= str2.length(); j++) {
                    if (str1.charAt(i-1) == str2.charAt(j-1)) {
                        dp[i][j] = dp[i-1][j-1] + 1;
                    }
                }
            }
            //找到dp最大值、即代表最长公共子序列的长度、同时记录下索引
            int max = 0;
            int index1 = 0;//横
            int index2 = 0;//竖
            for (int i = 0; i <=str1.length(); i++) {
                for (int j = 0; j <=str2.length(); j++) {
                    if (dp[i][j] > max) {
                        max = dp[i][j];
                        index1 = i;
                        index2 = j;
                    }
                }
            }
            StringBuffer stringBuffer = new StringBuffer();
            for (int i = index1-1; i >=index1-max; i--) {
                stringBuffer.append(str1.charAt(i));
            }
            System.out.println(stringBuffer.reverse());
        }
    }
}
